<#include "/main.ftl"/>
<@diamondNav/>
<body>
<div id="content" style="margin-left: 13%">
    <div style="margin-top: 5%;margin-left: 1%;width: 100%">


        <#if interfaceTest.interfaceId??>
            <form action="/interfaceTestController/updateInterfaceTest"
        <#else >
             <form action="/interfaceTestController/addInterfaceTest"
        </#if>

                   method="post" id="myForm" class="form-horizontal" >
        <div class="form-group">
            <label class="col-md-2 control-label" for="interfaceAliasName">接口别名</label>
            <div class="col-md-3">
                <input class="form-control" name="interfaceAliasName" type="text" id="interfaceAliasName"
                       placeholder="接口别名"
                       value="<#if interfaceTest?? && interfaceTest.interfaceAliasName ??>${interfaceTest.interfaceAliasName!}</#if>"/>
                 <#if interfaceTest??>
                     <@spring.bind "interfaceTest.interfaceAliasName" />
                     <span style="color: red"> <@spring.showErrors ""/> </span>
                 </#if>
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label" for="interfaceName">
             <#if interfaceTest??>
                <#if interfaceTest.interfaceType =="dubbo">
                接口名称
                <#else >
                   url
                </#if>
             <#else >
                 url
             </#if></label>
            <div class="col-md-3">
                <input class="form-control" name="interfaceName" type="text" id="interfaceName" placeholder="接口名称"
                       value="<#if interfaceTest?? && interfaceTest.interfaceName ??>${interfaceTest.interfaceName!}</#if>"/>
                 <#if interfaceTest??>
                     <@spring.bind "interfaceTest.interfaceName" />
                     <span style="color: red"> <@spring.showErrors ""/> </span>
                 </#if>
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label" for="interfaceMethod">方法</label>
            <div class="col-md-3">
                 <#if  interfaceTest.interfaceType =="dubbo">
                        <input class="form-control" type="text" name="interfaceMethod"
                        value="<#if interfaceTest?? && interfaceTest.interfaceMethod ??>${interfaceTest.interfaceMethod!}</#if>">
                 <#else >
                        <select class="form-control" title="大魔王" id="interfaceMethod" name="interfaceMethod">
                            <option value="GET" <#if interfaceTest.interfaceMethod?? && interfaceTest.interfaceMethod =="GET">selected="selected"</#if>>GET</option>
                            <option value="POST" <#if interfaceTest.interfaceMethod?? && interfaceTest.interfaceMethod =="POST">selected="selected"</#if>>POST</option>
                        </select>
                 </#if>
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label" for="encoding">编码</label>
            <div class="col-md-3">
                <select class="form-control" title="编码" id="encoding" name="encoding">
                    <option value="UTF-8" <#if interfaceTest.encoding?? && interfaceTest.encoding =="UTF-8">selected="selected"</#if>>UTF-8</option>
                    <option value="GBK" <#if interfaceTest.encoding?? && interfaceTest.encoding =="GBK">selected="selected"</#if>>GBK</option>
                </select>
            </div>
        </div>
        <#if  interfaceTest.interfaceType !="dubbo">
            <div class="form-group">
                <label class="col-md-2 control-label" for="hostId">host</label>
                <div class="col-md-3">
                    <select class="form-control" title="编码" id="hostId" name="hostId">
                        <option value="-1">不绑定host</option>
                        <#list hosts as h>
                            <option value="${h.id}"
                            <#if interfaceTest.hostId?? && interfaceTest.hostId ==h.id>selected</#if>
                            >${h.ip} ${h.domain} </option>
                        </#list>
                    </select>
                </div>
            </div>
        </#if>
        <div class="form-group">
            <label for="desc" class="control-label col-md-2">描述</label>
            <div class="col-md-3">
                <textarea id="interfaceTestDesc" name="interfaceDesc" class="form-control"
                          placeholder="接口描述">
                <#if interfaceTest?? && interfaceTest.interfaceDesc ??>${interfaceTest.interfaceDesc!}</#if>
                </textarea>
            </div>
        </div>
        <#if interfaceTest??>
            <#if  interfaceTest.interfaceType !="dubbo">
                <div class="form-group">
                <label for="Header" class="control-label col-md-2">Header</label>
                <div id="headerDiv" class="col-md-10">
                        <#if interfaceTest.headers?? && interfaceTest.headers!=''>
                            <@writeKeyValue interfaceTest.headers/>
                         <#else >
                            <input type="hidden" id="paramIndex" value="0">
                        </#if>
                     </div>
                 </div>
            </#if>
        </#if>
        <div>
            <input type="hidden" name="headers" id="headers">
            <input id="interfaceType" name="interfaceType" type="hidden"
                   value="<#if interfaceTest?? && interfaceTest.interfaceType ??>${interfaceTest.interfaceType!}</#if>">
            <input name="interfaceId" type="hidden"
                   value="<#if interfaceTest?? && interfaceTest.interfaceId ??>${interfaceTest.interfaceId!}</#if>">
            <input name="projectId" type="hidden"
            value="<#if interfaceTest?? && interfaceTest.projectId ??>${interfaceTest.projectId!}</#if>">
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <button type="button" class="btn btn-success " id="back">
                    返回
                </button>
                <button type="button" class="btn btn-success " id="addHeader">
                    添加header
                </button>
                <button type="reset" class="btn btn-success ">
                    重置
                </button>
                <button type="submit" class="btn btn-success" onclick="oKeyValueUtil.writeParam()">
                    提交
                </button>
            </div>
        </div>
    </form>
    </div>
</div>
</body>

<script type="text/javascript">
    var oKeyValueUtil;
    $(function () {
        oKeyValueUtil=new KeyValueUtil();
        oKeyValueUtil.init($('#headerDiv'),$("#addHeader"), $("#headers"))
    });

    $("#back").click(function(){
        window.location.href="/interfaceTestController/interfaceTestPage";
    })
</script>